package com.ymatou.iapi.productmanager.service;


import com.google.common.reflect.TypeToken;
import com.ymatou.iapi.productmanager.parameter.ProductInListDtoBeanV2;
import com.ymatou.iapi.productmanager.parameter.QuerySellerProductBean;
import com.ymt.core.tool.FormatUtil;
import com.ymttest.business.YmatouAutoTestCall;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.compare.CallAPI;
import org.json.JSONObject;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class QuerySellerProductListCall extends YmatouAutoTestCall  implements CallAPI{
	private static String opurl ="api/SellerProduct/QuerySellerProductList";
	
	public QuerySellerProductListCall() {
		super(EnvSetup.getSystemUrl("productmanager"),opurl,"POST","JSON");
	}
	@Override
	public void addDefHeader() {
		client.addHeader("Content-Type", "application/json; charset=UTF-8");
	}

	
	public static void main(String[] args){
		new QuerySellerProductListCall().callAndGetReturnData();
	}
	@Override
	public JSONObject callAndReturn(Map<String, Object> paramMap) {
		QuerySellerProductBean querySellerProductBean =  new QuerySellerProductBean();
		querySellerProductBean.setProductIdList(Arrays.asList(paramMap.get("productId").toString()));
		querySellerProductBean.setSellerId(Integer.parseInt(paramMap.get("sellerId").toString()));
		return callAndGetReturnData(querySellerProductBean);
	}
	@Override
	public String getApiName() {
		return "QuerySellerProductList";
	}
	
	public List<ProductInListDtoBeanV2> getProductList(){
		String ProductList= getJsonObject().get("Data").getAsJsonObject().get("ProductList").getAsJsonArray().toString();
		List<ProductInListDtoBeanV2> pProductList=(List<ProductInListDtoBeanV2>)FormatUtil.GSONToObject(ProductList, new TypeToken<List<ProductInListDtoBeanV2>>(){}.getType());
		return pProductList;
	}
}